﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Linq;
using System.Text;
using DomainDriver.DomainModeling.DomainObjects;
using DomainDriver.DomainModeling.StorageManagers.DataSetStorage;
using DomainDriver.DomainModeling.StorageManagers.EntityFrameworkStorage;
using ObjectRow = AutomotivePricingModel.AutomotivePricingDataSet.BrandsRow;

namespace AutomotivePricingModel.Brands
{
    public partial class Brand : IEfEntity<Guid>, IDataSetSerializable<AutomotivePricingDataSet, DataRow>
    {
        #region ADO .NET Entities Framework Storage

        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public Guid EF_Key
        {
            get { return m_Key; }
            set { m_Key = value; }
        }

        #endregion

        #region AutomotivePricingDataSet Serialization

        string IDataSetSerializable<AutomotivePricingDataSet, DataRow>.ObjectTableName
        {
            get { return AutomotivePricingDataSet.SchemaHelper.Brands.TableName; }
        }

        string IDataSetSerializable<AutomotivePricingDataSet, DataRow>.KeyColumnName
        {
            get { return AutomotivePricingDataSet.SchemaHelper.Brands.EF_BrandIdColumn.ColumnName; }
        }

        void IDataSetSerializable<AutomotivePricingDataSet, DataRow>.Serialize(AutomotivePricingDataSet datasource, DataRow dataRow)
        {
            ObjectRow objectRecord = dataRow as ObjectRow;

            objectRecord.EF_BrandId = m_Key;
            DataSetSerializationUtilities.SerializeNullableField<DateTime>(m_BrandCreationDate, objectRecord, AutomotivePricingDataSet.SchemaHelper.Brands.BrandCreationDateColumn);
            DataSetSerializationUtilities.SerializeNullableField<Guid>(m_CountryOfOrigin, objectRecord, AutomotivePricingDataSet.SchemaHelper.Brands.CountryOfOriginColumn);
            objectRecord.Name = m_Name;
            DataSetSerializationUtilities.SerializeNullableField<Guid>(m_OwningCompany, objectRecord, AutomotivePricingDataSet.SchemaHelper.Brands.OwningCompanyColumn);
        }

        void IDataSetSerializable<AutomotivePricingDataSet, DataRow>.Deserialize(AutomotivePricingDataSet datasource, DataRow dataRow)
        {
            ObjectRow objectRecord = dataRow as ObjectRow;

            m_Key = objectRecord.EF_BrandId;
            DataSetSerializationUtilities.DeserializeNullableField<DateTime>(out m_BrandCreationDate, objectRecord, AutomotivePricingDataSet.SchemaHelper.Brands.BrandCreationDateColumn);
            DataSetSerializationUtilities.DeserializeNullableField<Guid>(out m_CountryOfOrigin, objectRecord, AutomotivePricingDataSet.SchemaHelper.Brands.CountryOfOriginColumn);
            m_Name = objectRecord.Name;
            DataSetSerializationUtilities.DeserializeNullableField<Guid>(out m_OwningCompany, objectRecord, AutomotivePricingDataSet.SchemaHelper.Brands.OwningCompanyColumn);
        }

        #endregion
    }
}